<!DOCTYPE html>
<html lang="zh_CN">
<head>
<#-- 包含其他文件的内容 -->
    <#include "../common/header.ftl"/>
    <script src="/js/ckeditor/ckeditor.js"></script>

    <script>
        $(function () {
            //新增/修改
            $(".inputBtn").click(function () {
                //清空表单
                $("#editForm")[0].reset();
                $("#coverImg").attr('src','');
                var json = $(this).data('json');
                if(json) {
                    $("input[name='id']").val(json.id);
                    $("input[name='title']").val(json.title);
                    $("#coverImg").attr('src', json.coverUrl);//用来看的
                    $("input[name='coverUrl']").val(json.coverUrl);//提交表单的
                    $("select[name='catalog.id']").val(json.catalogId);
                    $("select[name='state']").val(json.state);

                }
                //显示模态框
                $("#inputModal").modal('show');
            });

            //提交表单
            $(".submitBtn").click(function () {
               //发送ajax请求
                $("#editForm").ajaxSubmit(function (data) {
                    handleResult(data);
                })
            })
        });
    </script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
        <#-- 往数据模型中填充一个属性 -->
            <#assign menu="productBrand"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">品牌管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/productBrand/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword"
                           value="${(qo.keyword)!}" placeholder="请输入品牌">
                    <label>状态:</label>
                    <select class="form-control" name="state" id="stateSelect">
                        <option value="-2">全部状态</option>
                        <option value="0">默认</option>
                        <option value="1">热门</option>
                        <option value="-1">禁用</option>
                    </select>
                    <script>
                        $("#stateSelect").val(${qo.state!});
                    </script>
                    <label>目录:</label>
                    <select class="form-control" name="catalogId" id="catalogSelect">
                        <option value="-1">全部目录</option>
                                <#list catalogs as c>
                                    <option value="${c.id}">${c.title}</option>
                                </#list>
                    </select>
                    <script>
                        $("#catalogSelect").val(${(qo.catalogId)!});
                    </script>
                </div>
                <button id="btn_query" class="btn btn-default">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a role="button" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>编号</th>
                    <th>品牌</th>
                    <th>封面</th>
                    <th>所属目录</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            <#-- 循环迭代指令 -->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index +1}</td>
                        <td>${entity.title}</td>
                        <td><img src="${entity.coverUrl}" width="50px"/></td>
                        <td>${entity.catalog.title}</td>
                        <td>${entity.stateName}</td>
                        <td>
                            <a class="btn btn-info btn-xs inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>

<!-- 模态框必须作为body的子标签 -->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/productBrand/saveOrUpdate.do" method="post" id="editForm">

                    <input type="hidden" name="id">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">品牌：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverImg" width="100%"/>
                            <input type="hidden" name="coverUrl">
                            <input type="file" class="form-control" name="file">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">所属目录：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="productCatalogSelect" name="catalog.id">
                                <option value="-1">全部目录</option>
                                <#list catalogs as c>
                                    <option value="${c.id}">${c.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="state">
                                <option value="0">默认</option>
                                <option value="1">热门</option>
                                <option value="-1">禁用</option>
                            </select>
                        </div>
                    </div>

                </form>


            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    <span class="glyphicon glyphicon-off"></span> 关闭
                </button>
                <button type="button" class="btn btn-primary submitBtn">
                    <span class="glyphicon glyphicon-saved"></span> 保存
                </button>
            </div>
        </div>
    </div>
</div>

<style>
    #showContentModal img {
        width: 100%
    }
</style>

</body>
</html>